/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFOnlineTask
  \brief to create histograms upon user demands and pass them to GUI system
  also responsible for initiate the GUI system
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2023-07-01
  \date 2023-07-01 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2023-07-01   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFOnlineTask_h
#define ETFOnlineTask_h

#include <string>
#include <vector>
#include "ETFTask.h"

using std::string;
using std::vector;

class TH1;
class ETFGOnline;
class ETFYaml;


class ETFOnlineTask : public ETFTask{
public:
  ETFOnlineTask(const char *name = "onlineTask");
  virtual ~ETFOnlineTask();

  /// hists by TTree::Project
  struct hcmd_t{
    TH1 *hist;
    // opt: draw option; ph: "+" + name, group: the hist group
    string hname, varexp, cut, opt, group;
    int ev0; ///< for drawing with fTree, the starting ev_id to draw from
  };
  virtual void Init() override;
  virtual void Exec() override {}
  virtual void Update();
  virtual void CreateHistos() override {}
  virtual void AddHistos(); ///< add histos to online GUI
  virtual void LoadConfigFile(); ///< load config file to update the hist list

  /// add 1D hists through online.yaml \param grp: the hist group defined in online GUI
  virtual void AddHist(const string &grp, const string &varexp, const string &hname,
    int nbinsx, double xlow, double xup, const string &cut = "",
    const string &opt = "colz");
  /// add 2D hists through online.yaml \param grp: the hist group defined in online GUI
  virtual void AddHist(const string &grp, const string &varexp, const string &hname,
    int nbinsx, double xlow, double xup,
    int nbinsy, double ylow, double yup, const string &cut = "",
    const string &opt = "colz"); ///< for 2D histos

protected:
  virtual bool hasHist(const string &hname);

  const ETFYaml *fConfig; ///< paras in online.yaml
  vector<hcmd_t *> fHCMDs, fHists; ///< hists from definitions in online.yaml, and the plain one
  ETFGOnline *fGOnline;
};

#endif
